﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using RouteTiming.Data;
using RouteTiming.DynamicModel;

namespace RouteTiming.WPFTest
{

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

/*
            var ctx = this.DataContext as RouteTimingContext;

            var routeId = new Guid("{3FDA9509-30B0-4FC7-A3E1-4A2D70151569}");
            var route = ctx.RouteSet.Single(r => r.Id == routeId);

            this.dataGrid.DataContext = route;

            
*/
//            this.dataGrid.DataContext = ((ObjectQuery)query).Execute(MergeOption.OverwriteChanges);
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            var ctx = this.DataContext as DynamicContext;

            var evt = new Event();

            evt.EventType = EventType.PointPass;
            evt.TimeRaised = DateTime.Now;
            evt.RoutePointId = Guid.Parse("{3FDA9509-30B0-4FC7-A3E1-4A2D70151567}");

            ctx.Context.EventSet.AddObject(evt);

            ctx.Context.SaveChanges();

/*
            var rp = new RoutePoint();
            rp.Id = Guid.NewGuid();
            rp.Name = "TestPoint";

            var route = (Route) this.dataGrid.DataContext;

            route.Points.Add(rp);

            ctx.SaveChanges();
 */ 
        }
    }
}
